popover: Forward key events to focus widget while visible/modal
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 25 Nov 2014 12:54:25 +0000 (13:54 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Tue, 25 Nov 2014 13:08:34 +0000 (14:08 +0100)
This is the expected behavior while the popover keeps the grab, leaving
this up to the toplevel implementation gives place to key handlers
connected there to handle the event otherwise, and maybe redirect key
events somewhere else.

gtk/gtkpopover.c

index 550aa1457a7db058f053c6296dc387480fb74cc3..241eef5e1f17a7a90011af75b2660874e6c3cb90 100644 (file)
@@ -1200,12 +1200,27 @@ static gboolean
 gtk_popover_key_press (GtkWidget   *widget,
                        GdkEventKey *event)
 {
+  GtkWidget *toplevel, *focus;
+
   if (event->keyval == GDK_KEY_Escape)
     {
       gtk_widget_hide (widget);
       return GDK_EVENT_STOP;
     }
 
+  if (!GTK_POPOVER (widget)->priv->modal)
+    return GDK_EVENT_PROPAGATE;
+
+  toplevel = gtk_widget_get_toplevel (widget);
+
+  if (GTK_IS_WINDOW (toplevel))
+    {
+      focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
+
+      if (focus && gtk_widget_is_ancestor (focus, widget))
+        return gtk_window_propagate_key_event (GTK_WINDOW (toplevel), event);
+    }
+
   return GDK_EVENT_PROPAGATE;
 }